package com.hello.sky.controller.admin;

import com.hello.sky.exception.SkyException;
import com.hello.sky.model.dto.EmployeeDTO;
import com.hello.sky.model.dto.PageParamDto;
import com.hello.sky.model.dto.PasswordEditDTO;
import com.hello.sky.model.entity.Employee;
import com.hello.sky.model.vo.UserReportVO;
import com.hello.sky.result.PageResult;
import com.hello.sky.result.Result;
import com.hello.sky.service.EmployeeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 员工信息 前端控制器
 * </p>
 *
 * @author D
 */
@Slf4j
@Tag(name = "员工")
@RestController
@RequestMapping("/admin/employee")
public class EmployeeController {

    @Autowired
    private EmployeeService  employeeService;

    @Operation(summary = "员工登录")
    @PostMapping("/login")
    public Result login(@RequestBody Employee employee){
        return employeeService.login(employee);
    }

    @Operation(summary = "修改密码")
    @PutMapping("/editPassword")
    public Result editPassword(@RequestBody PasswordEditDTO passwordEditDTO){
        employeeService.editPassword(passwordEditDTO);
        return Result.success();
    }

    @Operation(summary = "启用、禁用员工账号")
    @PostMapping("/status/{status}")
    public Result updateStatusById(@PathVariable(name = "status") Integer status, @RequestParam("id") Long id){
        employeeService.updateStatusById(status, id);
        return Result.success();
    }

    @Operation(summary = "员工分页查询")
    @GetMapping("/page")
    public Result<PageResult> getPage(PageParamDto params){
        PageResult page = employeeService.getPage(params);
        return Result.success(page);
    }

    @Operation(summary = "新增员工")
    @PostMapping
    public Result addEmp(@RequestBody EmployeeDTO employee){
        employeeService.addEmp(employee);
        return Result.success();
    }

    @Operation(summary = "根据id查询员工")
    @GetMapping("/{id}")
    public Result addEmp(@PathVariable("id") Long id){
        Employee employee = employeeService.getEmpById(id);
        return Result.success(employee);
    }

    @Operation(summary = "编辑员工信息")
    @PutMapping
    public Result updateEmp(@RequestBody Employee employee){
        employeeService.updateEmp(employee);
        return Result.success();
    }

    @Operation(summary = "退出登录")
    @PostMapping(" /logout")
    public Result updateEmp(){
        //todo 退出登录
        return Result.success();
    }


}
